import {ElMessage, ElMessageBox} from "element-plus";
import {getRequest} from "@/util/api";

export function message(msg, type) {
    ElMessage({
        message: msg,
        showClose: true,
        type: type,
        center: true,
        duration: 3000
    })
}

export function confirmBox(tipMsg, resolve) {
    ElMessageBox.confirm(tipMsg, 'Warning', {confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning',}
    ).then(() => {
        resolve();
    }).catch(() => {
    });
}

export function flushLocalStorage() {
    localStorage.removeItem("token");
    localStorage.removeItem("refreshToken");
    localStorage.removeItem("username");
    localStorage.removeItem("password");
    localStorage.removeItem("avatarUrl");
}

export async function generateDownloadUuid(resolve) {
    await getRequest("/download/generateDownloadToken", null, (res) => {
        resolve(res.data.data);
    });
}
